package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.DiseaseBean;
import com.project.service.DiseaseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 病害
 */
@Controller
@RequestMapping("disease")
public class DiseaseController {


    @Resource
    private DiseaseService diseaseService;


    /**
     * 显示所有病害信息
     * @param pageNO
     * @param pageSize
     * @return
     */
    @RequestMapping("/findAllDisease")
    @ResponseBody
    public IPage<DiseaseBean> findAllDisease(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                          @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return diseaseService.findAllDisease(pageNO, pageSize);
    }


    /**
     * 添加新病害
     * @param diseaseBean
     * @return
     */
    @RequestMapping("addDisease")
    @ResponseBody
    public String addDisease(DiseaseBean diseaseBean) {
        diseaseService.addDisease(diseaseBean);
        return "添加成功";
    }


    /**
     * 查看详细信息
     * @param diseaseId
     * @return
     */
    @RequestMapping("findId")
    @ResponseBody
    public DiseaseBean findId(int diseaseId) {
        return diseaseService.findId(diseaseId);
    }

    /**
     * 模糊查询
     * @param pageNO
     * @param pageSize
     * @param diseaseName
     * @param diseaseSymptom
     * @return
     */
    @RequestMapping("findName")
    @ResponseBody
    public IPage<DiseaseBean> findName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String diseaseName, String diseaseSymptom) {
        return diseaseService.findName(pageNO, pageSize, diseaseName, diseaseSymptom);
    }
}
